<?php

/**
 * 评论控制器
 *
 */

namespace app\controllers\user;

use app\common\base\ApiController;
use app\common\behaviors\ApiCommonBehavior;


class CommentController extends ApiController
{
    /**
     * 获取自己的全部评论;
     */
    public function actionMyComment(){
        $userId = $this->userInfo->id;
        
        $info = ApiCommonBehavior::call('user', 'CommentService', 'lists', [
            'condition' => [
                'status' => 1,
                'user_account_id' => $userId,
            ]
        ]);

        return [
            'info' => $info,
        ];

    }

    /**
     * 获取指定影片的全部评论;
     */
    public function actionFilmComment(){
        $this->rules = [
            [['film_id'], 'required'],
            [['film_id'], 'integer'],
        ];
        $inputs = $this->validate();
        
        $info = ApiCommonBehavior::call('user', 'CommentService', 'lists', [
            'condition' => [
                'status' => 1,
                'film_id' => $inputs['film_id'],
            ]
        ]);

        return [
            'info' => $info,
        ];

    }

    /**
     * 添加评论;
     */
    public function actionAddComment(){
        $this->rules = [
            [['comment', 'film_id'], 'required'],
            [['comment'], 'string'],
            [['film_id'], 'integer'],
        ];
        $inputs = $this->validate();
        $userId = $this->userInfo->id;

        $info = ApiCommonBehavior::call('user', 'CommentService', 'addComment', 
            $inputs['comment'],
            $inputs['film_id'],
            $userId
        );

        return [
            'info' => $info,
        ];
    }

    /**
     * 删除评论;
     */
    public function actionDeleteComment(){
        $this->rules = [
            ['comment_id', 'required'],
            ['comment_id', 'integer'],
        ];
        $inputs = $this->validate();
        $userId = $this->userInfo->id;

        $info = ApiCommonBehavior::call('user', 'CommentService', 'DeleteComment', 
            $inputs['comment_id'],
            $userId
        );

        return [
            'info' => $info,
        ];
    }

}
